' // ***************************************************************************
' // 
' // Copyright (c) Microsoft Corporation.  All rights reserved.
' // 
' // Microsoft Deployment Toolkit Solution Accelerator
' //
' // File:      Summary_scripts.vbs
' // 
' // Version:   5.0.1641.0
' // 
' // Purpose:   Scripts to initialize and validate summary wizard
' // 
' // ***************************************************************************

Option Explicit


Function InitializeSummary

	Dim oLog
	Dim sLine
	Dim sMessage
	Dim sDetails
	Dim sType
	Dim bProcess
	Dim sBuffer

	Dim iErrors
	Dim iWarnings

	' If this is a replace, then modifiy the title

	if Property("DeploymentType") = "REPLACE" then
		NormalTitle.style.display = "none"
		ReplaceTitle.style.display = "inline"
	end if

	' Set the background color based on the return code

	If oEnvironment.Item("RETVAL") = "0" or oEnvironment.Item("RETVAL") = "" then
		' OK
	Else
		MyContentArea.style.backgroundColor = "salmon"
	End if


	' Make sure we can find a master log file.  If not, quit.

	If not oFSO.FileExists(oUtility.LogPath & "\" & oLogging.MasterLogFile) then

		ErrorCount.InnerText = "unknown"
		WarningCount.InnerText = ""

		oLogging.CreateEntry "Unable to find " & oUtility.LogPath & "\" & oLogging.MasterLogFile, LogTypeInfo
		Exit Function

	End if


	' Read each line of the log and count the errors and warnings

	iErrors = 0
	iWarnings = 0

	Set oLog = oFSO.OpenTextFile(oUtility.LogPath & "\" & oLogging.MasterLogFile)
	While not oLog.AtEndOfStream

		' Split apart the message

		bProcess = false
		sLine = oLog.ReadLine
		If Instr(sLine, "<![LOG[") > 0 then  ' Line beginning found

			If Instr(sLine, "]LOG]!>") = 0 then  ' No end label found, start of multiline message
				sMessage = Mid(sLine, 8)
			Else
				sMessage = Mid(sLine, 8, Instr(sLine, "]LOG]!>") - 8)
				sDetails = Mid(sLine, Instr(sLine, "]LOG]!>") + 7)
				sType = Mid(sDetails, Instr(sDetails, "type=""") + 6, 1)
				bProcess = true
			End if

		Else  ' No line beginning found, continuation

			If Instr(sLine, "]LOG]!>") = 0 then  ' No end label found, start of multiline message
				sMessage = sMessage & vbNewLine & sLine
			Else
				sMessage = sMessage & vbNewLine & Left(sLine, Instr(sLine, "]LOG]!>") - 1)
				sDetails = Mid(sLine, Instr(sLine, "]LOG]!>") + 7)
				sType = Mid(sDetails, Instr(sDetails, "type=""") + 6, 1)
				bProcess = true
			End if

		End if


		' Inspect the type

		If bProcess then

			' Add to the count

			Select Case sType
			Case "3"
				iErrors = iErrors + 1
			Case "2"
				iWarnings = iWarnings + 1
			End Select


			' Add the message to the details display

			If sType <> "1" then
				oStrings.AddToList sBuffer, sMessage, vbNewLine
			End if

		End if

	WEnd

	oLog.Close
	Set oLog = Nothing

	If oEnvironment.Item("RETVAL") <> "0" and (iErrors = 0 or iWarnings = 0) Then
		If oFSO.FileExists("X:\MININT\SMSOSD\OSDLOGS\BDD.LOG") Then
			Set oLog = oFSO.OpenTextFile("X:\MININT\SMSOSD\OSDLOGS\BDD.LOG")
			While not oLog.AtEndOfStream

				' Split apart the message

				bProcess = false
				sLine = oLog.ReadLine
				If Instr(sLine, "<![LOG[") > 0 then  ' Line beginning found

					If Instr(sLine, "]LOG]!>") = 0 then  ' No end label found, start of multiline message
						sMessage = Mid(sLine, 8)
					Else
						sMessage = Mid(sLine, 8, Instr(sLine, "]LOG]!>") - 8)
						sDetails = Mid(sLine, Instr(sLine, "]LOG]!>") + 7)
						sType = Mid(sDetails, Instr(sDetails, "type=""") + 6, 1)
						bProcess = true
					End if

				Else  ' No line beginning found, continuation

					If Instr(sLine, "]LOG]!>") = 0 then  ' No end label found, start of multiline message
						sMessage = sMessage & vbNewLine & sLine
					Else
						sMessage = sMessage & vbNewLine & Left(sLine, Instr(sLine, "]LOG]!>") - 1)
						sDetails = Mid(sLine, Instr(sLine, "]LOG]!>") + 7)
						sType = Mid(sDetails, Instr(sDetails, "type=""") + 6, 1)
						bProcess = true
					End if

				End if


				' Inspect the type

				If bProcess then

					' Add to the count

					Select Case sType
					Case "3"
						iErrors = iErrors + 1
					Case "2"
						iWarnings = iWarnings + 1
					End Select


					' Add the message to the details display

					If sType <> "1" then
						oStrings.AddToList sBuffer, sMessage, vbNewLine
					End if

				End if

			WEnd

			oLog.Close
			Set oLog = Nothing
		End If
	End If

		
	' Update the dialog

	ErrorCount.InnerText = CStr(iErrors)
	WarningCount.InnerText = CStr(iWarnings)
	optionalWindow1.InnerText = sBuffer
	buttonCancel.disabled = true


	' Set the background color to yellof if success and errors and warnings.

	If oEnvironment.Item("RETVAL") = "0" or oEnvironment.Item("RETVAL") = "" then
		If iErrors > 0 or iWarnings > 0 then
			MyContentArea.style.backgroundColor = "yellow"
		End if
	End if

End Function
